<?php

namespace app\index\controller;

use app\index\model\PcSoftInfo;
use think\Controller;
use think\Db;
use think\Request;

class Sort extends Controller
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        if($this->request->get('name')){
            $where['Name']      = ['like','%'.$this->request->get('name').'%'];
        }
        if($this->request->get('nav')){
            if($this->request->get('nav') != 9999){
                $category_id      = $this->request->get('nav');
                $where['CateId']    = ['=',$category_id];
            }

        }
        $limit            = $this->request->get('limit',10);
        $where['Status']    = ['=',PcSoftInfo::STATUS_1];
        // 查询分页数据
        $pc_soft_list = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->paginate($limit);
        $pc_soft_list_arr = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->paginate($limit)->toArray();
        $this->assign('pc_soft_list',$pc_soft_list);
//        dump($pc_soft_list);die;
        $cate_list_6 = Db::name('category_soft')->limit(6)->select();
        $cate_list_all = Db::name('category_soft')->select();
        $cate_name = Db::name('category_soft')->find($this->request->get('nav'));

        $host_search_list = Db::name('pc_soft_info')
            ->where('Status',1)
            ->where('hot_search','=',1)
            ->order('OrderBy','desc')
            ->limit(0,12)
            ->select();

        $good_evaluation_list = Db::name('pc_soft_info')
            ->where('Status',1)
            ->where('good_evaluation','=',1)
            ->order('OrderBy','DESC')
            ->limit(0,6)
            ->select();

        $nav_CateId = 9999;
        if(!$pc_soft_list_arr['data']){
            $nav_CateId = 9999;
        }

        $this->assign('host_search_list',$host_search_list);
        $this->assign('good_evaluation_list',$good_evaluation_list);
        $this->assign('nav',$this->request->get('nav') ? $this->request->get('nav') : $nav_CateId);
        $this->assign('cate_name',$cate_name['Name']);
        $this->assign('cate_list_6',$cate_list_6);
        $this->assign('cate_list_all',$cate_list_all);
        $this->assign('pc_soft_list',$pc_soft_list);
        $this->assign('pc_soft_list_arr_count',count($pc_soft_list_arr['data']));
        return $this->view->fetch();
    }


    public function index2()
    {

        if($this->request->get('name')){
            $where['Name']      = ['like','%'.$this->request->get('name').'%'];
        }
        if($this->request->get('CateId')){
            $category_id      = $this->request->get('CateId');
            $where['CateId']    = ['=',$category_id];
        }
        $limit            = $this->request->get('limit','30');
        $where['Status']    = ['=',PcSoftInfo::STATUS_1];
        // 查询分页数据
        $pc_soft_list = Db::name('pc_soft_info')->where($where)->order('id', 'desc')->paginate($limit);

        return json($pc_soft_list);
    }




}
